<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/commons/taglibs.jsp"%>
<%@ include file="/commons/commonEdit.jsp"%>
<%@ include file="/commons/tabs.jsp"%>
<%@ include file="/commons/validation.jsp"%>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>保证金补退核算</title>
<link href="${ctx}/css/grid.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="${ctx}/scripts/div/common.js"></script>
<script type="text/javascript" src="${ctx}/scripts/public.js"></script>
<script type="text/javascript" src="${ctx}/scripts/common/prototype.js"></script>
<script type="text/javascript" src="${ctx}/scripts/common.js"></script>
<script type="text/javascript" src="${ctx}/scripts/ajaxException.js"></script>
<script type="text/javascript">

		var ACTION_URL="${ctx}/renovation_depositAccountingAction.do?";

	function saveWin(){ //保存
		var isTrue=$("countDepositForm").fireEvent("onSubmit");
  		if(isTrue){
  			setButtonStatus(false);
			var params = $("countDepositForm").serialize();
			var url = ACTION_URL+"method=depositAndAmercement";
			sendAjaxRequest(url,params,function(response){

				setButtonStatus(true);

				ajaxSubmitException(response.responseText);
				findFrame('main').reflesh();  //刷新主页面列表
				windowClose();
			});
		}
	}


	function submitFun(){ //提交(先保存)
		var isTrue=$("countDepositForm").fireEvent("onSubmit");
  		if(isTrue){

  			setButtonStatus(false);

			var params = $("countDepositForm").serialize();
			var url = ACTION_URL+"method=depositAndAmercement";
			sendAjaxRequest(url,params,backSubmitWin);
		}
	}
	function backSubmitWin(response){//再提交
				setButtonStatus(true);
				ajaxSubmitException(response.responseText);
				findFrame('main').reflesh();  //刷新主页面列表

				var depositAccountingId=response.responseText;
				findFrame("depositAccountingListIfm").editSubmit(depositAccountingId); //提交
				windowClose();
	}


	function checkClientValue(){  //设置业主补退信息

		var clientDeposit = $('clientDeposit').value;  //业主押金
		var clientAmercementCount = $('clientAmercementCount').value;//业主累计罚款
		var clientFactAmercement=$('clientFactAmercement').value;//业主实际罚款

		var difference = clientDeposit - clientFactAmercement ;
		if (isNaN(difference) || isNaN(clientFactAmercement) || clientFactAmercement< 0 ){
			$('returnClientDeposit_span').innerText = "0"; //退还业主
			$('clientAddedAmercement_span').innerText = "0";  //补收业主
			$('returnClientDeposit').value="0";
			$('clientAddedAmercement').value="0";
		}else{
			if (difference >= 0){
				$('returnClientDeposit_span').innerText = difference.toFixed(2); //退还业主
				$('clientAddedAmercement_span').innerText = "0";  //补收业主
				$('returnClientDeposit').value=difference.toFixed(2);
				$('clientAddedAmercement').value="0";
			}else{
				$('returnClientDeposit_span').innerText = "0"; //退还业主
				$('clientAddedAmercement_span').innerText = Math.abs(difference).toFixed(2);  //补收业主
				$('returnClientDeposit').value="0";
				$('clientAddedAmercement').value=Math.abs(difference).toFixed(2);
			}
		}
		setStyle();
	}

	function checkcompanyValue(){  //设置公司补退信息

		var companyDeposit = $('companyDeposit').value;  //公司押金
		var companyAmercementCount = $('companyAmercementCount').value;//公司累计罚款
		var companyFactAmercement=$('companyFactAmercement').value;//公司实际罚款

		var difference = companyDeposit - companyFactAmercement ;  //押金 - 实际罚款
		if (isNaN(difference)|| isNaN(companyFactAmercement) || companyFactAmercement < 0){
			$('returnCompanyDeposit_span').innerText = "0"; //退还公司
			$('companyAddedAmercement_span').innerText = "0";  //补收公司
			$('returnCompanyDeposit').value="0";
			$('companyAddedAmercement').value="0";
		}else{
			if (difference >= 0){
				$('returnCompanyDeposit_span').innerText = difference.toFixed(2); //退还公司
				$('companyAddedAmercement_span').innerText = "0";  //补收公司
				$('returnCompanyDeposit').value=difference.toFixed(2);;
				$('companyAddedAmercement').value="0";
			}else{
				$('returnCompanyDeposit_span').innerText = "0"; //退还公司
				$('companyAddedAmercement_span').innerText = Math.abs(difference).toFixed(2);  //补收公司
				$('returnCompanyDeposit').value="0";
				$('companyAddedAmercement').value= Math.abs(difference).toFixed(2);
			}
		}
		setStyle();
	}


	function setStyle(){ //设置备注样式

		var clientAmercementCount = $('clientAmercementCount').value;//业主累计罚款
		var clientFactAmercement=$('clientFactAmercement').value;//业主实际罚款

		var companyAmercementCount = $('companyAmercementCount').value;//公司累计罚款
		var companyFactAmercement=$('companyFactAmercement').value;//公司实际罚款

		if (isNaN(clientFactAmercement) || isNaN(companyFactAmercement) ){  //如果公司，或个人输入实际罚款不为数字类型，备注必填
			$('remark_td').className="aux_intable_require_more";
			$('remark').className="required max-length-100";
		}else{
			if ((clientFactAmercement - clientAmercementCount) < 0  ||	(companyFactAmercement - companyAmercementCount) < 0 ){   //如果实际罚款小于罚款累计，则备注必填

					$('remark_td').className="aux_intable_require_more";
					$('remark').className="required max-length-100";

			}else{														 //如果实际罚款大于，等于罚款累计，则备注不作必填验证

					$('remark_td').className="aux_intable_td2";
					Validation.removeElmValidate('remark');
					$('remark').className="max-length-100";
			}
		}
	}

	function setButtonStatus(status){ //设置按钮状态 true 代表可用 false代表不可用
		$("btn1_12").disabled = !status;
		$("btn1_22").disabled = !status;
		$("btn1_32").disabled = !status;
	}

	function init(){
		checkClientValue();
		checkcompanyValue();
	}

</script>
</head>

<body onload="init();">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td class="window_head_outBg">
    <table border="0" cellpadding="0" cellspacing="0">
      <tr>
        <td><img src="${ctx}/images/ico_Advance.gif" width="16" height="16" align="absmiddle" /> <span class="window_head_intext">保证金补退核算</span></td>
      </tr>
    </table>
    </td>
  </tr>
  <tr><td class="aux_header_line_1"></td></tr>
  <tr><td class="aux_header_line_2"></td></tr>
  <tr>
    <td valign="middle" class="content">
    <table width="100%" border="0" cellpadding="0" cellspacing="0" class="container_in_show">
      <tr>
        <td valign="top">

<form id="countDepositForm" name="countDepositForm" action="" method="post" class="required-validate" >
<input id="licenceId" name="licenceId" type="hidden" value="${accountingVO.licenceId }">
<input id="inspectionRequistionId" name="inspectionRequistionId" type="hidden" value="${accountingVO.inspectionRequistionId }">
<input id="keyword" name="keyword" type="hidden" value="${accountingVO.keyword }">
            <div id="tab_Search">
			<div id="tab_subMenu1" style="display:show;">
               <table width="100%" border="0" align="center" cellpadding="5" cellspacing="0">
                  <tr>
                     <td>
                     <table width="100%" border="0" cellpadding="0" cellspacing="1" class="aux_intable_color">
                          <tr>
			                <td class="aux_intable_td1">业主押金：</td>
			                <td class="aux_intable_td2">${accountingVO.clientDeposit == null ? 0 :accountingVO.clientDeposit }&nbsp;元	<input id="clientDeposit" name="clientDeposit" type="hidden" value="${accountingVO.clientDeposit == null ? 0 :accountingVO.clientDeposit }"></td>
			                <td class="aux_intable_td1">装修公司押金：</td>
			                <td class="aux_intable_td2">${accountingVO.companyDeposit == null ? 0 :accountingVO.companyDeposit }&nbsp;元<input id="companyDeposit" name="companyDeposit" type="hidden" value="${accountingVO.companyDeposit == null ? 0 :accountingVO.companyDeposit }"></td>
			              </tr>

						  <tr>
			                <td class="aux_intable_td1">业主累计罚款：</td>
			                <td class="aux_intable_td2">${accountingVO.clientAmercementCount == null ? 0 : accountingVO.clientAmercementCount }&nbsp;元<input id="clientAmercementCount" name="clientAmercementCount" type="hidden" value="${accountingVO.clientAmercementCount == null ? 0 : accountingVO.clientAmercementCount }"></td>
			                <td class="aux_intable_td1">装修公司累计罚款：</td>
			                <td class="aux_intable_td2">${accountingVO.companyAmercementCount == null ? 0 : accountingVO.companyAmercementCount}&nbsp;元<input id="companyAmercementCount" name="companyAmercementCount" type="hidden" value="${accountingVO.companyAmercementCount == null ? 0 : accountingVO.companyAmercementCount}"></td>
			              </tr>
			              <tr>
			                <td class="aux_intable_td1">业主实际罚款：</td>
			                <td class="aux_intable_td2"><input name="clientFactAmercement" id="clientFactAmercement" onchange="checkClientValue();" type="text" class="inputtext float-zero-right integer-decimal-range-10-2" value="${accountingVO.clientFactAmercement != null ? accountingVO.clientFactAmercement : accountingVO.clientAmercementCount}" style="text-align:right" size="16" /> 元</td>
			                <td class="aux_intable_td1">装修公司实际罚款：</td>
			                <td class="aux_intable_td2"><input name="companyFactAmercement" id="companyFactAmercement" onchange="checkcompanyValue();" type="text" class="inputtext float-zero-right integer-decimal-range-10-2" value="${accountingVO.companyFactAmercement != null ?accountingVO.companyFactAmercement : accountingVO.companyAmercementCount}" style="text-align:right" size="16" />元</td>
			              </tr>
			              <tr>
			                <td class="aux_intable_td1">退还业主：</td>
			                <td class="aux_intable_td2">
			                	<input id="returnClientDeposit" name="returnClientDeposit" type="hidden" value="${accountingVO.returnClientDeposit} ">
			                	<span id="returnClientDeposit_span"> ${accountingVO.returnClientDeposit }</span>元</td>
			                <td class="aux_intable_td1">退还装修公司：</td>
			                <td class="aux_intable_td2">
			                	<input id="returnCompanyDeposit" name="returnCompanyDeposit" type="hidden" value="${accountingVO.returnCompanyDeposit }">
			                	<span id="returnCompanyDeposit_span">${accountingVO.returnCompanyDeposit }</span>元</td>
			              </tr>
			              <tr>
			                <td class="aux_intable_td1">补收业主：</td>
			                <td class="aux_intable_td2">
			                	<input id="clientAddedAmercement" name="clientAddedAmercement" type="hidden" value="${accountingVO.clientAddedAmercement }">
			                	<span id="clientAddedAmercement_span">${accountingVO.clientAddedAmercement }</span> 元</td>
			                <td class="aux_intable_td1">补收装修公司：</td>
			                <td class="aux_intable_td2">
			                	<input id="companyAddedAmercement" name="companyAddedAmercement" type="hidden" value="${accountingVO.companyAddedAmercement }">
			                	<span id="companyAddedAmercement_span">${accountingVO.companyAddedAmercement }</span>元</td>
			              </tr>
			              <tr>
			                <td valign="top" class="aux_intable_td1">备 注：</td>
			                <td colspan="3" id="remark_td"  class="aux_intable_td2"><textarea name="remark" id="remark" cols="26" rows="3" value="" class="max-length-100">${accountingVO.remark }</textarea>
			                </td>
			              </tr>
                        </table>
                        </td>
                      </tr>
                </table>
            </div>
			</div>
</form>

		</td>
      </tr>
    </table>
	</td>
  </tr>
  <tr>
    <td class="window_footer"><table border="0" cellpadding="0" cellspacing="0">
      <tr>
	   <td><table border="0" cellpadding="0" cellspacing="0">
          <tr>
            <td class="buttonOffLeft" id="btn1_11"></td>
            <td class="buttonOffMiddle" id="btn1_12" onClick="submitFun();" onMouseOver="btn_change_over(1)" onMouseOut="btn_change_out(1)" onBlur="btn_change(1)"><img src="${ctx}/images/ico_submit.gif" alt="" width="14" height="14" border="0" align="absbottom" /> 提 交</td>
            <td class="buttonOffRight" id="btn1_13"></td>
          </tr>
        </table></td>
        <td class="btn_between_space"></td>
        <td><table border="0" cellpadding="0" cellspacing="0" >
            <tr>
              <td class="buttonOffLeft" id="btn1_21"></td>
              <td class="buttonOffMiddle" id="btn1_22" onblur="btn_change(2)" onMouseOver="btn_change_over(2)" onMouseOut="btn_change_out(2)" onClick="saveWin();"><img src="${ctx}/images/ico_ok.gif" border="0" align="absmiddle" /> 保 存</td>
              <td class="buttonOffRight" id="btn1_23"></td>
            </tr>
        </table></td>
        <td class="btn_between_space"></td>
        <td><table border="0" cellpadding="0" cellspacing="0" onClick="windowClose();">
            <tr>
              <td class="buttonOffLeft" id="btn1_31"></td>
              <td class="buttonOffMiddle" id="btn1_32" onblur="btn_change(3)" onMouseOver="btn_change_over(3)" onMouseOut="btn_change_out(3)"><img src="${ctx}/images/ico_cancel.gif" border="0" align="absmiddle" /> 关 闭</td>
              <td class="buttonOffRight" id="btn1_33"></td>
            </tr>
        </table></td>
      </tr>
    </table></td>
  </tr>
</table>
</body>
</html>